#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define max_len 100
#define max_fragments 50

void split_into_fragments(const char* dna, char fragments[][max_len], int* fragment_count)
{
	const char* pattern1 = "CCCGGG";
	const char* pattern2 = "GGGCCC";
	int pattern_len = 6;
	int len = strlen(dna);
	int pos = 0;
	*fragment_count = 0;
	int i;
	for (i = 0; i <= len - pattern_len; i++) {
		if (strncmp(dna + i, pattern1, pattern_len) == 0 || strncmp(dna + i, pattern2, pattern_len) == 0) {
			strncpy(fragments[*fragment_count], dna + pos, i + 3 - pos);
			fragments[*fragment_count][i + 3 - pos] = '\0';
			(*fragment_count)++;
			pos = i + 3;
		}
	}
	strncpy(fragments[*fragment_count], dna + pos, len - pos);
	fragments[*fragment_count][len - pos] = '\0';
	(*fragment_count)++;
}

void reverse_and_join(char fragments[][max_len], int fragment_count, char* result)
{
	result[0] = '\0';
	int i;
	for (i = fragment_count - 1; i >= 0; i--) {
		strcat(result, fragments[i]);
	}
}

int main()
{
	char dna1[max_len + 1] = "CCGGAAGGGCCC";
	char dna2[max_len + 1] = "GGCCTTCCCGGG";
	char fragments1[max_fragments][max_len];
	char fragments2[max_fragments][max_len];
	int fragment_count1, fragment_count2;
	split_into_fragments(dna1, fragments1, &fragment_count1);
	split_into_fragments(dna2, fragments2, &fragment_count2);
	char reversed_dna1[max_len * 2] = { 0 };
	char reversed_dna2[max_len * 2] = { 0 };
	reverse_and_join(fragments1, fragment_count1, reversed_dna1);
	reverse_and_join(fragments2, fragment_count2, reversed_dna2);
	printf("%s\n", reversed_dna1);
	printf("%s\n", reversed_dna2);
	return 0;
}
